

using System;
using System.Collections.Generic;
using System.Text;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.Managers;
using Tathata.Common.BLL.EntityCollections;

namespace Tathata.Common.BLL.Managers
{
    /// <summary>
    /// Tax manager
    /// </summary>
    public class TaxManager
    {
        #region Methods
     

        /// <summary>
        /// Gets a tax rate
        /// </summary>
        /// <param name="address">Address</param>
        /// <param name="TaxCategoryID">The tax category identifier</param>
        /// <returns>Tax rate</returns>
        protected static decimal GetTaxRate(Address address, int TaxCategoryID)
        {
            int CountryID = 0;
            int StateProvinceID = 0;

            if (address.Country != null)
            {
                CountryID = address.Country.CountryID;
            }
            if (address.StateProvince != null)
            {
                StateProvinceID = address.StateProvince.StateProvinceID;
            }
            decimal tr = decimal.Zero;
            TaxByCountry taxByCountry = TaxByCountryManager.GetAllByCountryID(CountryID).GetByTaxCategoryID(TaxCategoryID);
            if (taxByCountry != null)
                tr += taxByCountry.Percentage;
            TaxByStateProvince taxByStateProvince = TaxByStateProvinceManager.GetAllByStateProvinceID(StateProvinceID).GetByTaxCategoryID(TaxCategoryID);
            if (taxByStateProvince != null)
                tr += taxByStateProvince.Percentage;
            return tr;
        }
        #endregion
    }
}
